<?php
class ml_tool_tagfilter
{
    static public function filter($tag)
    {
        $arrDelete = array(',',' ','　');
        return trim(str_replace($arrDelete , '' , $tag));
    }
    static public function filter_tag_by_tag($from, $target){
        if(!is_array($from) || !is_array($target))
            return false;
        foreach($from as $key=>$value){
            if(!in_array(ml_tool_resid::str_hash($value['tag']), $target) || !$value['content'])
                unset($from[$key]);
        }
        if(is_array($from) && count($from)>0){
            $from = array_slice($from, 0, 4);
            return $from;
        }else{
            return false;
        }
    }
    static public function righttag($tgid, $show_tag=null){
        if(empty($show_tag))
            $show_tag = ml_tool_getdata::mlJsonData('guanghottag','tagdata');
        $righttag = ml_tool_getdata::mlJsonData('righttag_'.$tgid,'righttag');
        $righttag['relateds'] = self::filter_tag_by_tag($righttag['relateds'], array_keys($show_tag));
        $righttag['groups'] = self::filter_tag_by_tag($righttag['groups'], array_keys($show_tag));
        if(!$righttag['relateds'] && !$righttag['groups'] && empty($righttag['albums']))
            return false;
        else
            return $righttag;
    }
}